﻿@model CardInChina.Bussiness.Frontend.Models.UserInfoShowInWidget
<div class="user" id="user_widget">
    @if (Model.IsAuthenticated)
    {
        <div class="lm">
            <h2>
                用户中心</h2>
        </div>
        <div class="user_list">
            <div class="user_list_bg">
                <div class="user-detail">
                    <div>欢迎回来, 亲爱的游龙网会员</div>
                    <div><a href="/user" title="查看我的用户中心"><b>@Model.UserName</b></a> (<span>普通会员</span>)</div>
                    <div>账户余额: <a href="/user/savings" title="查看账户详情">0 元</a> (状态, <a href="/user/deposit" title="进入充值页面">充值</a>)</div>
                    <div><a href="/user/order" title="查看我的所有订单信息">我的订单</a></div>
                    <div><a href="/user/favorite" title="进入我的收藏页面">我的收藏</a></div>
                    <div><a href="/user/logout" title="退出登录">退出登录</a></div>
                    <div><a href="/user" title="查看我的用户中心">更多信息</a></div>
                </div>
            </div>
        </div>
        <div class="lb">
        </div>
    }
    else
    {
        <div class="lm">
            <h2>
                用户中心</h2>
        </div>
        <div class="user_list" id="user_list">
            <div class="user_list_bg">
                <div class="dl-usr">
                    <table>
                        <tbody>
                            <tr>
                                <td class="l">
                                    会员帐号
                                </td>
                                <td>
                                    <input name="userName" id="userName" type="text" class="" onfocus="this.className='on'"
                                        onblur="this.className=''" />
                                </td>
                            </tr>
                            <tr>
                                <td class="l">
                                    会员密码
                                </td>
                                <td>
                                    <input name="password" id="password" type="password" class="" onfocus="this.className='on'"
                                        onblur="this.className=''" maxlength="30" />
                                </td>
                            </tr>
                            <tr>
                                <td class="l">
                                    验证码
                                </td>
                                <td>
                                    <input name="validatecode" id="validatecode" type="text" class="validatecode" />
                                    <img id="validatecodeimg" src="@Url.Action("GetValidateCode", "Widget")" alt="hip code" title="看不清？点击换一张" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                    <a href="/user/forgotpwd">？找回密码</a>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                    <div class="join-usr">
                        <input name="userJoin" id="userJoin" type="button" class="ui-icons join_position demo_button"
                            value="会员注册" />
                        <input name="submitBtn" id="submitBtn" type="submit" class="ui-icons submit_position demo_button"
                            value="登 录" />
                    </div>
                </div>
            </div>
        </div>
        <div class="lb">
        </div>
        
        <script type="text/javascript">
            $(function () {

                @if (Model.Msg != null) { 
                    @:window.alert("@Model.Msg");
                }

                // deal with velidate image
                $("#validatecodeimg").hip();

                // deal with register button
                $("#userJoin").click(function () {
                    window.location.href = "/user/register";
                });

                // deal with login button
                $("#submitBtn").click(function () {

                    var userName = $.trim($("#userName").val());
                    if (!userName) {
                        alert("请输入用户名");
                        $("#userName").focus();
                        return;
                    }

                    var pwd = $.trim($("#password").val());
                    if (!pwd) {
                        alert("请输入密码");
                        $("#password").focus();
                        return;
                    }

                    var validCode = $.trim($("#validatecode").val());
                    if (!validCode) {
                        alert("请输入验证码");
                        $("#validatecode").focus();
                        return;
                    }

                    var remember = "";

                    params = '{userName:"' + userName + '",pwd:"' + pwd + '",validCode:"' + validCode + '",remember:"' + remember + '"}';
                    $.ajax({
                        type: "POST",
                        cache: false,
                        url: "/widget/userinfo",
                        data: params,
                        dataType: "html",
                        contentType: "application/json; charset=utf-8",
                        beforeSend: function () {
                            $("#user_list").html("<img src=\"/content/images/loading.gif\" />");
                        },
                        success: function (result) {
                            $("#user_widget").html(result);
                        },
                        error: function (xhr, msg, e) {
                            alert(msg);
                        }
                    });
                });

                // deal with edit box 'enter' keydown
                $("#userName, #password, #validatecode").keydown(function (e) {
                    if(e.keyCode == '13') {
                        e.preventDefault();
                        $("#submitBtn").click();
                    }
                });
            });
        </script>
    }
</div>
